package com.itheima.homework6;

import java.util.concurrent.Semaphore;

public class MyRunnable implements Runnable {
    private Semaphore sp = new Semaphore(2);
    @Override
    public void run() {
        try {
            sp.acquire();
            System.out.println("获得通行证，继续前行");
            Thread.sleep(200);
            System.out.println("归还通行证");
            sp.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
